﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Sagacity.NC.Web.FormForm;
using Coolite.Ext.Web;

namespace Sagacity.NC.Web.BasicSettings.Student
{
    public partial class StudentBaseInfo : PageBase
    {
        public int resourceId = 0;
        public string action = string.Empty;
        public int regionId = 0;
        public int schoolId = 0;
        public int showStyle = 0;
        int studentId = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            resourceId = Request.QueryString["ResourceId"] == null ? 0 : int.Parse(Request.QueryString["ResourceId"]);
            schoolId = Request.QueryString["SchoolId"] == null ? 0 : int.Parse(Request.QueryString["SchoolId"]);
            int showStyle = Request.QueryString["showStyle"] == null ? 0 : int.Parse(Request.QueryString["showStyle"]);
            
             studentId = Request.QueryString["StudentId"] == null ? 0 : int.Parse(Request.QueryString["StudentId"]);
            int controlType = Request.QueryString["controlType"] == null ? 0 : int.Parse(Request.QueryString["controlType"]);

            action = Request.QueryString["Action"] == null ? "" : Request.QueryString["Action"];
            regionId = Request.QueryString["RegionId"] == null ? 0 : int.Parse(Request.QueryString["RegionId"]);

            if (schoolId != 0)
            {
                Sagacity.Entity.Query.ParameterInfo param = new Sagacity.Entity.Query.ParameterInfo() { ParameterName = "School_ID", RealValue = schoolId };
                this.HostFormCommon1.ModelParams.Add(param);
            }
            Sagacity.Entity.Query.ParameterInfo param2 = new Sagacity.Entity.Query.ParameterInfo() { ParameterName = "Student_ID", RealValue = studentId };
            this.HostFormCommon1.ModelParams.Add(param2);
            this.HostFormCommon1.CurrentUser = CurrentUser;
            this.HostFormCommon1.Role = CurrentUser.LoginRole;
            this.HostFormCommon1.ShowPlan = (ShowPlan)showStyle;
            this.HostFormCommon1.ResourceId = resourceId;

            if (controlType != 1)
                this.HostFormCommon1.ReadOnly = true;

            AddButton();
        }
        public void AddButton()
        {
            //增加按钮
            Coolite.Ext.Web.ToolbarButton btnAdd = new Coolite.Ext.Web.ToolbarButton();
            btnAdd.ID = "btnPassword";
            btnAdd.Visible = true;
            btnAdd.Enabled = true;
            btnAdd.Text = "初始化密码";
            btnAdd.Icon = Icon.Add;
            btnAdd.Listeners.Click.Handler = "javascript:PassWordFunction();";
            HostFormCommon1.BtnControls.Add(btnAdd);
        }

        [AjaxMethod]
        public bool InitPassWord()
        {
            string query =string.Format( @"update ee_base_StudentInfo set LoginPass='111111' where student_ID={0}" , studentId);
            Hashtable Table=new Hashtable();
           string log = string.Format(@"insert into CFG_LOG (RESOURCE_ID,DATA_ID,OPERATORTYPE,OPERATORID,OPERATORDATE)
                        values({0},{1},{2},{3},'{4}')", resourceId,
                          studentId, 1, CurrentUser.LoginRole.Id, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                   
           return Sagacity.NC.Business.SysMange.Common.ExcuteFormCommand(query, Table, log);

        }

    }
}
